﻿function AutoCloseDialog(confirm, msg) {
    if (event.keyCode == 27) {
        if (confirm != null && confirm) {
            if (window.confirm(msg)) {
                window.close();
            }
        }
        else {
            window.close();
        }
    }
}

function ReadOnly_onkeydown(obj, obj2_id) {
    if (event.keyCode == 46) {
        obj.value = "";
        var obj2 = document.getElementById(obj2_id);
        if (obj2 != null) {
            obj2.value = "";
        }
    }
}

function changeView(obj) {
    if (document.all("div_" + obj).style.display == "block") {
        document.all("div_" + obj).style.display = "none";
        document.all("ico_" + obj).src = "/Themes/Default/ico_have.gif";
    }
    else {
        document.all("div_" + obj).style.display = "block";
        document.all("ico_" + obj).src = "/Themes/Default/ico_nohave.gif";
    }

    defaultView = obj;
}

function SetToCenter(obj, fullScreen) {
    if (obj == null) {
        return;
    }

    if (fullScreen) {
        obj.style.left = 0;
        obj.style.top = 0;

        obj.style.width = document.body.scrollWidth;
        obj.style.height = document.body.scrollHeight;

        obj.style.backgroundColor = "#D4D0C8";
    }
    else {
        obj.style.left = document.body.scrollWidth / 2 - obj.scrollWidth / 2;
        obj.style.top = document.body.scrollHeight / 2 - obj.scrollHeight / 2;
    }
}

// 检查货币
function CheckPrice(obj) {
    return obj != null && !isNaN(obj.value);
}

// 检查当前页面是否在Iframe中打开，若是的话，将父窗口作为本窗口打开
function CheckIsInFrame() {
    if (window.frameElement != null) {
        window.parent.location = window.location.href;
    }
}

// “更多操作”菜单方法：显示菜单
function ShowMoreAction(obj, menuID, delay) {
    var delayTime = delay / 2;
    var actionMenu = document.getElementById(menuID);

    if (delay > 0) {
        var timerID = window.setTimeout("CloseMoreAction('" + menuID + "', " + delayTime + ");", delayTime);
        actionMenu.onmouseenter = function () {
            window.clearTimeout(timerID);
        }
        actionMenu.onmouseover = actionMenu.onmouseenter;
    }

    // 退出条件
    actionMenu.onmouseout = function () {
        CloseMoreAction(menuID, 500);
    }

    // 计算菜单位置
    actionMenu.style.position = "absolute";
    actionMenu.style.left = event.clientX - actionMenu.scrollWidth;
    actionMenu.style.top = event.clientY;
    actionMenu.style.display = "block";
}

// “更多操作”菜单方法：关闭菜单
function CloseMoreAction(menuID, delayTime) {
    var actionMenu = document.getElementById(menuID);
    if (delayTime > 0) {
        var timerID = window.setTimeout("CloseMoreAction('" + menuID + "', 0)", delayTime);
        actionMenu.onmouseenter = function () {
            window.clearTimeout(timerID);
        }
        actionMenu.onmouseover = actionMenu.onmouseenter;
    }
    else {
        actionMenu.style.display = "none";
    }
}

function OpenWin(sURL, sFeatures) {
    window.open(sURL, null, sFeatures, null)
    //window.open("Sample.htm",null,"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
    //window.open( [sURL] [, sName] [, sFeatures] [, bReplace])
    //sName{_blank; _media; _parent; _search; _self; _top}
    //sFeatures{channelmode; directories; fullscreen; height; left; location; menubar; resizable; scrollbars; status; titlebar; toolbar; top; width} 
}

function ShowWin(sURL, sFeatures) {
    var result = window.showModalDialog(sURL, null, sFeatures);

    return result;
    //window.showModalDialog("Sample.htm",null,"dialogHeight:591px;dialogWidth:650px;")
    //window.showModalDialog([sURL] [, vArguments] [, sFeatures])
    //sFeatures{dialogHeight; dialogLeft; dialogTop; dialogWidth; center; dialogHide; edge; help; resizable; scroll; status; unadorned}
}

// 打开密码重置窗口
function OpenPasswordResetForm(obj, actorType, actorId) {
    var sFeature = "dialogHeight:280px; dialogWidth:420px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/SystemManagement/Organization/ResetPassword.aspx?Type=" + actorType + "&ActorID=" + actorId + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 打开物资申请限制窗口
function OpenMaterialApplyLimitSettingForm(obj, mId) {
    var sFeature = "dialogHeight:450px; dialogWidth:500px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/MaterialManagement/MaterialApplyLimitSetting.aspx?mid=" + mId + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出上传文件页
function OpenFileUploader(obj, module, fileType, maxSize, fileID) {
    var sFeature = "dialogHeight:280px; dialogWidth:420px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Common/ApplicationPages/UploadFile.aspx?Module=" + encodeURIComponent(module) + "&MaxSize=" + maxSize + "&FType=" + fileType + "&FID=" + fileID + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出上传文件页
function OpenFileUploaderWithFile(fileName, fileLink) {
    var result = window.showModalDialog("/common/applicationpages/uploadfile.aspx?DocuName=" + encodeURI(fileName) + "&DocuLink=" + encodeURI(fileLink), null, "dialogheight: 450px; dialogwidth: 650px; dialogtop: px; dialogleft: px; edge:raised; center: yes; help: yes; resizable: yes; status: no;");

    CallResultComand(result);

    return result;
}

// 弹出部门选择框，查找部门
function SelectDepts(obj, mode, selected) {
    var sFeature = "dialogHeight:600px; dialogWidth:800px; center:yes; resizable:yes; scroll:no; status:no;";
    var url = "/Common/ApplicationPages/UserSelector.aspx?mode=" + mode + "&selected=" + selected + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 选择部门
//mode:SingleSelector/MutilSelector
function SelectDepts(mode, selected) {
    var sFeature = "dialogHeight:600px; dialogWidth:800px; center:yes; resizable:yes; scroll:no; status:no;";
    var url = "/Common/ApplicationPages/UserSelector.aspx?mode=" + mode + "&selected=" + selected + "&selectorMode=org&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出用户选择框，查找用户
function SelectActors(obj, mode, selected) {
    var sFeature = "dialogHeight:600px; dialogWidth:800px; center:yes; resizable:yes; scroll:no; status:no;";
    var url = "/Common/ApplicationPages/UserSelector.aspx?mode=" + mode + "&selected=" + selected + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}
// 弹出用户选择框，查找用户
function SelectActorsWithWindowTitle(obj, mode, selected,title) {
    var sFeature = "dialogHeight:600px; dialogWidth:800px; center:yes; resizable:yes; scroll:no; status:no;";
    var url = "/Common/ApplicationPages/UserSelectorWithTitle.aspx?mode=" + mode + "&selected=" + selected + "&title=" + title + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}
// 设置成员角色
function OpenUserRoleSetting(obj, actorID, actorType) {
    var sFeature = "dialogHeight:395px; dialogWidth:450px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/SystemManagement/Organization/UserRoleSetting.aspx?ActorID=" + actorID + "&ActorType=" + actorType + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出角色设置
function OpenRoleForm(obj, action, roleID) {
    var sFeature = "dialogHeight:250px; dialogWidth:450px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/SystemManagement/Organization/RoleForm.aspx?Action=" + action + "&id=" + roleID + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出物资类别详细页
function OpenMaterialClassForm(obj, action, mClassID, paramsStr) {
    var p = "";
    if (paramsStr != null) {
        p = paramsStr;
        if (p.indexOf("&") != 0) {
            p = "&" + p;
        }
    }

    var sFeature = "dialogHeight:300px; dialogWidth:450px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/MaterialManagement/MaterialClassForm.aspx?Action=" + action + "&id=" + mClassID + p + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出物资类别选择框
function OpenMaterialClassSelector(obj, mode, selected) {
    var sFeature = "dialogHeight:500px; dialogWidth:450px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Common/ApplicationPages/MaterialClassSelector.aspx?mode=" + mode + "&selected=" + selected + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出物资选择框
function OpenMaterialSelector(obj, mode, selected) {
    var sFeature = "dialogWidth:900px;dialogHeight:760px;  center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Common/ApplicationPages/MaterialSelector.aspx?mode=" + mode + "&selected=" + selected + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出物资信息详细页
function OpenMaterialInfoForm(obj, action, ID) {
    var sFeature = "dialogHeight:390px; dialogWidth:720px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/MaterialManagement/MaterialInfoForm.aspx?Action=" + action + "&id=" + ID + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出配送商信息详细页
function OpenSupplierForm(obj, action, ID) {
    var sFeature = "dialogHeight:350px; dialogWidth:720px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/SupplierManagement/SupplierForm.aspx?Action=" + action + "&id=" + ID + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出配送商选择框
function OpenSupplierSelector(obj, mode, selected) {
    var sFeature = "dialogHeight:550px; dialogWidth:770px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Common/ApplicationPages/SupplierSelector.aspx?mode=" + mode + "&selected=" + selected + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出批量导入物资信息页
function OpenImportMaterials(obj) {
    var sFeature = "dialogHeight:230px; dialogWidth:420px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/MaterialManagement/ImportMaterialInfo.aspx?rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出批量导入物资报价页
function OpenImportMaterialPrices(obj) {
    var sFeature = "dialogHeight:230px; dialogWidth:420px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/MaterialManagement/ImportMaterialPrice.aspx?rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    result = CallResultComand(result);

    return result;
}

// 弹出系统参数设置框
function OpenSystemConfigForm(obj, mode, configID) {
    var sFeature = "dialogHeight:250px; dialogWidth:400px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/SystemManagement/SystemSettingForm.aspx?mode=" + mode + "&configID=" + configID + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 处理对话框返回命令
function CallResultComand(result) {
    if (result == null || result == "") {
        return false;
    }

    var resArray = result.split("#;");
    for (var index = 0; index < resArray.length; index++) {
        var res = resArray[index];

        if (res.indexOf("Call:") >= 0) {
            var cmdArray = res.split(":");
            if (cmdArray.length >= 2) {
                var cmd = new Function(cmdArray[1]);
                try {
                    cmd();
                }
                catch (e) { }
            }
        }
        else if (res.indexOf("Refresh:Normal") >= 0) {
            window.location = window.location.href;
        }
        else if (res.indexOf("Refresh:Replace") >= 0) {
            window.location.replace(window.location.href);
        }
        else if (res.indexOf("Refresh:Reload") >= 0) {
            window.location.reload(true);
        }
        else {
            result = res;
        }
    }

    return result;
}

// 复选框全选
function SelectAll(obj, selectorName) {
    if (obj == null || obj.statue == null || selectorName == "") {
        return;
    }

    var statue = obj.getAttribute("statue").toLowerCase() == "true";
    statue = !statue;
    obj.statue = statue.toString();

    var selectors = document.getElementsByName(selectorName);
    for (var index = 0; index < selectors.length; index++) {
        selectors[index].checked = statue;
    }

    if (statue) {
        obj.innerText = "取消";
    }
    else {
        obj.innerText = "全选";
    }
}

function UpdateSelectedItem(obj, valueHolderID) {
    if (obj == null) {
        return;
    }

    var SelectedValCtrl = document.getElementById(valueHolderID);
    var SelectedItemCtrls = document.getElementsByName(obj.name);
    var SelectedItems = "";

    for (var index = 0; index < SelectedItemCtrls.length; index++) {
        if (SelectedItemCtrls[index].checked) {
            SelectedItems += SelectedItemCtrls[index].value + ";";
        }
    }

    if (SelectedItems != "") {
        SelectedItems = SelectedItems.substring(0, SelectedItems.length - 1);
    }

    SelectedValCtrl.value = SelectedItems;

    return SelectedItems;
}

function InitSelector(selectorName, valueHolderID) {
    var valueHolder = document.getElementById(valueHolderID);
    var selectors = document.getElementsByName(selectorName);

    if (valueHolder == null || selectors.length == 0) {
        return;
    }

    var selectedValueStr = valueHolder.value.toUpperCase();
    for (var index = 0; index < selectors.length; index++) {
        var currentValue = selectors[index].value.toUpperCase();
        if (selectedValueStr.indexOf(currentValue) >= 0) {
            selectors[index].checked = true;
        }
        else {
            selectors[index].checked = false;
        }
    }
}

// 弹出项目信息详细页
function OpenProjectInfoForm(obj, action, ID) {
    var sFeature = "dialogHeight:270px; dialogWidth:720px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/SupplierManagement/ProjectInfoForm.aspx?Action=" + action + "&id=" + ID + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}

// 弹出合同信息详细页
function OpenContractInfoForm(obj, action, ID) {
    var sFeature = "dialogHeight:380px; dialogWidth:720px; center:yes; resizable:no; scroll:no; status:no;";
    var url = "/Modules/SupplierManagement/ContractInfoForm.aspx?Action=" + action + "&id=" + ID + "&rnd=" + Math.random();

    var result = window.showModalDialog(url, null, sFeature);
    CallResultComand(result);

    return result;
}


//网页打印时清空页眉页脚
function pagesetup_null() {
    try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\header", "");
        RegWsh.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\footer", "");
    } catch (e) {
    }
}

//网页打印的时恢复页眉页脚为默认值
function pagesetup_default() {
    try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\header", "&w&b页码，&p/&P");
        RegWsh.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\footer", "&u&b&d");        
    } catch (e) {
    }
}

function doPrintToNewWindiow(printDiv) {
    try {
        pagesetup_null();

        newwin = window.open("", "newwin", "height=" + window.screen.height + ",width=" + window.screen.width + ",toolbar=no,scrollbars=auto,menubar=no");
        newwin.document.body.innerHTML = document.getElementById(printDiv).innerHTML;
        newwin.window.print();
        newwin.window.close();
        
        //pagesetup_default();
    } catch (e) { }
}

function doPrint(printArea) {
    try {
        pagesetup_null();

        var body = document.body.innerHTML;
        document.body.innerHTML = document.getElementById(printArea).innerHTML;
        window.print();
        document.body.innerHTML = body;

        //pagesetup_default();
    } 
    catch (e) { }
}
//以上是打印代码

//展示对应的流程说明及图片
var current_show_flow_id = "";
function showFlowImg(flowId) {
    if (current_show_flow_id != "")
        document.getElementById(current_show_flow_id).style.display = "none";
    document.getElementById(flowId + "_Img").style.display = "";
    current_show_flow_id = flowId + "_Img";
}

//发起申请页面，tab页提示
function showTips(typeId) {
    var typeName = "";
    var typeDesc = "";
    if (typeId == 1) {
        typeName = "什么是低值易耗品？";
        typeDesc = "办公物资中金额<b>不大于2千元</b>的为低值易耗品。";
    }
    else
        if (typeId == 2) {
            typeName = "什么是非网资产？";
            typeDesc = "办公物资中金额<b>大于或等于2千元</b>的为非网资产。";
        }
        document.getElementById("FlowTypeName").innerHTML = typeName;
        document.getElementById("FlowTypeDesc").innerHTML = typeDesc;
        document.getElementById("tabTips").style.visibility = "visible";
    }

    function hideTips() {
        document.getElementById("tabTips").style.visibility = "hidden";
    }

    function createXMLDocument(string) {
        var browserName = navigator.appName;
        var doc;
        if (browserName == 'Microsoft Internet Explorer') {
            doc = new ActiveXObject('Microsoft.XMLDOM');
            doc.async = 'false'
            doc.loadXML(string);
        } else {
            doc = (new DOMParser()).parseFromString(string, 'text/xml');
        }
        return doc;

    }